package com.sgxy.wmservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sgxy.servicebase.exceptionhandler.ERPException;
import com.sgxy.wmservice.entity.WmInputOrder;
import com.sgxy.wmservice.entity.WmOrders;
import com.sgxy.wmservice.entity.vo.OrdersVo;
import com.sgxy.wmservice.mapper.WmOrdersMapper;
import com.sgxy.wmservice.service.WmInputOrderService;
import com.sgxy.wmservice.service.WmOrdersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-04-29
 */
@Service
public class WmOrdersServiceImpl extends ServiceImpl<WmOrdersMapper, WmOrders> implements WmOrdersService {

    @Autowired
    private WmInputOrderService wmInputOrderService;

    @Override
    public IPage<OrdersVo> selectPageVoList(IPage<OrdersVo> page, WmOrders wmOrders) {
        return baseMapper.selectPageVoList(page,wmOrders);
    }

    @Override
    public OrdersVo selectOneById(String id) {
        return baseMapper.selectOneById(id);
    }

    @Override
    public Boolean deleteById(String id) {
        QueryWrapper<WmInputOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("input_id",id);
        int count = wmInputOrderService.count(wrapper);
        if(count>0){
            throw new ERPException(20001,"该数据正被使用，无法删除");
        }
        baseMapper.deleteById(id);
        return true;
    }
}
